package com.mini.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * Created by shixi  on 2020/9/10
 */
@Entity(name = "business_tradition_chance")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@DynamicUpdate
@DynamicInsert
public class BusinessTraditionChance implements Serializable {

    private static final long serialVersionUID = -5142975848079627189L;
    /**
     * id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @ApiModelProperty(value = "系统来源： 0 投放 2手工导入")
    private Integer systemFrom;

    /**
     * 飞天站点
     */
    @ApiModelProperty(value = "飞天站点")
    private Long miniSiteId;
    /**
     * 飞天站点名称
     */
    @ApiModelProperty(value = "飞天站点名称")
    private String miniSiteName;

    /**
     * 机会状态
     */
    @ApiModelProperty(value = "机会状态,-1:未分配 0：未跟进 1:跟进中 2:已报名")
    private Integer chanceStatus;

    /**
     * 意向
     */
    @ApiModelProperty(value = "意向 未知:-1/无: 0/低:1/中:2/高:3")
    private Integer intentionCode;

//    @ApiModelProperty(value = "广告渠道")
//    private Integer channelId;


    @ApiModelProperty(value = "量子军团id")
    private Long quantumLegionId;

    /**
     * 运营专员Id
     */
    @ApiModelProperty(value = "运营专员Id")
    private Long teacherId;
    /**
     * 运营专员名称
     */
    @ApiModelProperty(value = "运营专员名称")
    private String teacherName;

    @ApiModelProperty(value = "咨询师微信号")
    private String teacherWxNo;

    @ApiModelProperty(value = "咨询师手机号")
    private String teacherPhone;

    /**
     * 学员昵称
     */
    @ApiModelProperty(value = "学员昵称")
    private String studentNickname;

    /**
     * 项目id
     */
    @ApiModelProperty(value = "项目id")
    private Integer itemId;
    /**
     * 省
     */
    @ApiModelProperty(value = "省")
    private String province;

    @ApiModelProperty(value = "省id")
    private String provinceId;
    /**
     * 市
     */
    @ApiModelProperty(value = "市")
    private String city;
    @ApiModelProperty(value = "市id")
    private String cityId;

    @ApiModelProperty(value = "反馈时间(机会状态从未跟进变为跟进中的的时间)")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    Date feedbackTime;

    @ApiModelProperty(value = "未分配原因")
    private String assignNotReason;

    @ApiModelProperty(value = "分配类型，0系统分配 1人工分配 2转归属")
    private Integer distributeType;

    @ApiModelProperty(value = "分配时间(若未分配状态则显示空)")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    Date distributeTime;
    /**
     * 末次跟进时间
     */
    @ApiModelProperty(value = "末次跟进时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastFollowUpTime;

    @ApiModelProperty(value = "末次有效跟进时间(发微信/打电话)")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastValidFollowUpTime;

    @ApiModelProperty(value = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(insertable = false, updatable = false)
    Date updateTime;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(insertable = false, updatable = false)
    Date createTime;

    @ApiModelProperty(value = "拨打次数（包括未打通）")
    private Integer callNum;

    //今日拨打次数
    @ApiModelProperty(value = "今日拨打次数（包括未打通）")
    private Integer todayCallNum;

    //今日微信条数
    @ApiModelProperty(value = "今日微信条数，咨询师发给学员的")
    private Integer todayChatNum;

    @ApiModelProperty(value = "加微状态")
    private Boolean isAdd;
    /************************下面是四张关联表的信息****************************************/

    @ApiModelProperty(value = "手机号联系方式集合")
    @OneToMany()
//    @JoinColumnsOrFormulas(value =
//            {@JoinColumnOrFormula(column = @JoinColumn(name = "id", referencedColumnName = "chance_id",insertable = false,updatable = false)),
////                    @JoinColumnOrFormula(column = @JoinColumn(name = "teacherId", referencedColumnName = "teacherId",insertable = false,updatable = false))
//            })
    @JoinColumn(name="chance_id",referencedColumnName="id",insertable = false,updatable = false)
    private List<BusinessChancePhone> phoneList;

    @OneToMany()
    @ApiModelProperty(value = "微信号联系方式集合")
//    @JoinColumnsOrFormulas(value =
//            {@JoinColumnOrFormula(column = @JoinColumn(name = "id", referencedColumnName = "chanceId",insertable = false,updatable = false)),
////                    @JoinColumnOrFormula(column = @JoinColumn(name = "teacherId", referencedColumnName = "teacherId",insertable = false,updatable = false))
//            })
    @JoinColumn(name="chance_id",referencedColumnName="id",insertable = false,updatable = false)
    private List<BusinessChanceWechat> wechatList;

    @ApiModelProperty(value = "今日拨打次数记录")
    @OneToMany()
    @JoinColumnsOrFormulas(value =
            {@JoinColumnOrFormula(column = @JoinColumn(name = "chance_id", referencedColumnName = "id",insertable = false,updatable = false)),
                    @JoinColumnOrFormula(column = @JoinColumn(name = "teacherId", referencedColumnName = "teacherId",insertable = false,updatable = false))
            })
    private List<BusinessChancePhoneRecord> phoneRecord;

    @ApiModelProperty(value = "今日微信条数记录")
    @OneToMany()
    @JoinColumnsOrFormulas(value =
            {@JoinColumnOrFormula(column = @JoinColumn(name = "chance_id", referencedColumnName = "id",insertable = false,updatable = false)),
                    @JoinColumnOrFormula(column = @JoinColumn(name = "teacherId", referencedColumnName = "teacherId",insertable = false,updatable = false))
            })
    private List<BusinessChanceWechatRecord> wechatRecord;

}
